// Better way to create new objects
// Takes an object parameter to inherit from
window.object = function (o) {
	var F = function (){};
	F.prototype = o;
	return new F();
};

// A better typeof that understands Date objects, Arrays, and null.

window.typeOf = function (value) {
    var t = typeof(value);
    if (t === "object") {
        // Check for some types that typeof doesn't handle well
		if (value === null) {
			t = "undefined";
		} else if (value instanceof Date) {
			t = "date";
		} else if (value instanceof String) {
			t = "string";
		} else if (value instanceof Number) {
			t = "number";
		} else if (value instanceof Boolean) {
			t = "boolean";
		} else if (value instanceof Array) {
			t = "array";
		}
    }
    return t;
};

// Checks to see if a value is undefined or null
window.isUndefined = function(value) {
	var type = typeOf(value);
	
	return type === "undefined" || type === "null";
};


// A named format function. Takes a string: "Your name is {name}. Your age is {age}" and a matching object: { name: "John", age: 10 }
window.format = function (s, o) {
    return s.replace(/{([^{}]*)}/g,
        function (a, b) {
            var r = o[b];
            return (typeOf(r) === "string" || typeOf(r) === "number") ? r : a;
        }
    );
};

// Trims white space from the beginning and end of a string
window.trim = function (s) {
    return s.replace(/^\s+|\s+$/g, "");
}; 